This post explains how you can set the locale in R to handle Norwegian characters (æ, ø, å) properly.
This post was all wrong earlier. So I have rewritten it myself. Since “Bokmål” includes an “å”, the locale was reverted to “C” by Rstudio. To make it work on a computer that has Norwegian Bokmål as the system language you have to specify the type of UTF-8 without the word “bokmål”.1. Thus the correct specification to work if you write in Norwegian is:
Sys.setlocale(category = "LC_ALL", locale = "NO_NB.utf8")
[1] "LC_COLLATE=NO_NB.utf8;LC_CTYPE=NO_NB.utf8;LC_MONETARY=NO_NB.utf8;LC_NUMERIC=C;LC_TIME=NO_NB.utf8"
For more information in Norwegian see here on my home page.
To make it standard you can put it in the r-profile. You open the profile:
#install.packages("usethis")
usethis::edit_r_profile()
And enter the locale:
Sys.setlocale(category = "LC_ALL", locale = "NO_NB.utf8")
[1] "LC_COLLATE=NO_NB.utf8;LC_CTYPE=NO_NB.utf8;LC_MONETARY=NO_NB.utf8;LC_NUMERIC=C;LC_TIME=NO_NB.utf8"
I learned this here: https://github.com/rstudio/rstudio/issues/15008↩︎
For attribution, please cite this work as
Solheim (2024, Dec. 20). Solheim: Handling Norwegian Characters (æ, ø, å) in R. Retrieved from https://www.oyvindsolheim.com/library/Norwegian characters/
BibTeX citation
@misc{solheim2024handling,
author = {Solheim, Øyvind Bugge},
title = {Solheim: Handling Norwegian Characters (æ, ø, å) in R},
url = {https://www.oyvindsolheim.com/library/Norwegian characters/},
year = {2024}
}